package pl.edu.agh.neuraleconomy.ui.chart;

import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;

import lombok.Data;
import pl.edu.agh.neuraleconomy.core.ta.indicator.Indicator;
import pl.edu.agh.neuraleconomy.model.exchange.Exchange;
import pl.edu.agh.neuraleconomy.ui.chart.provider.ISerieProvider;
import pl.edu.agh.neuraleconomy.ui.chart.provider.SerieProviderFactory;
import pl.edu.agh.neuraleconomy.ui.types.PredictionDataComposite;

@Data
public class ChartBean {
	private String chartName = "";
	private List<SerieBean> series = new LinkedList<SerieBean>();
	PredictionDataComposite predictionComposite = null;
	
	
	public ChartBean(EnumSet<Indicator> indicators, List<Exchange> exchanges){
		prepareSeries(indicators, exchanges);
	}
	
	public ChartBean(EnumSet<Indicator> indicators, List<Exchange> exchanges, PredictionDataComposite predictionComposite){
		this.predictionComposite = predictionComposite;
		prepareSeries(indicators, exchanges);
	}
	
	private void addSerie(SerieBean serie){
		series.add(serie);
	}
	
	private void prepareSeries(EnumSet<Indicator> indicators, List<Exchange> exchanges){
		for(Indicator i : indicators){
			ISerieProvider serieProvider = SerieProviderFactory.getProvider(i);
			SerieBean serie = serieProvider.getSerie(exchanges);
			addPrediction(serie, serieProvider);
			addSerie(serie);
		}
	}
	
	private void addPrediction(SerieBean serieBean, ISerieProvider serieProvider){
		if(predictionComposite != null){
			serieBean.setPredictionSerie(serieProvider.getPrediction(predictionComposite));
		}
	}
	
	
}
